import baseUrl from "./baseUrl.js"

var http = function(config) {
	return new Promise((resolve, reject) => {
		const headers = {
			'token': uni.getStorageSync('token'), // 默认 token
			...config.headers, // 合并传入的 headers (包含 cityid)
		};
		uni.request({
			url: `${baseUrl}/index.php/api${config.url}`,
			data: config.data,
			method: config.method,
			header: headers,
			success: res => {
				if (res.data.code == 401) {
					uni.navigateTo({
						url: `/pages/user/userLogin`
					})
					uni.clearStorage()
					return
				}
				resolve(res.data)
			},
			fail(err) {
				reject(err)
			},
		})
	})
}
export default http